from django.shortcuts import render
from rest_framework.generics import ListCreateAPIView
from rest_framework.views import APIView
from rest_framework.response import Response
from category_group.models import *
from category_group.ser import *


class CategoryView(ListCreateAPIView):
    queryset = Category.objects.all()
    serializer_class = CategorySer
    lookup_field = 'id'
    lookup_url_kwarg = 'id'


class AddGroup(APIView):
    def post(self, request):
        name = request.data.get('name')
        cate = request.data.get('cate')
        group_url = request.data.get('group_url')
        sequence = request.data.get('sequence')

        if not all([name, cate, group_url, sequence]):
            return Response({
                'code': 400,
                'msg': '数据不全'
            })
        print('>>>', cate)
        # try:
        #     Category.objects.get('cate')


class GroupView(ListCreateAPIView):
    queryset = Group.objects.all()
    serializer_class = GroupSer








